import wx_opendata from "./wx/wx_opendata";
import GameController from "./game_controller";
import constants from "./constants";
import UIController from "./ui_controller";
import global from "./global";

// Learn TypeScript:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/typescript.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    @property(cc.Node)
    rankingFriend3: cc.Node = null;//显示排行榜

    @property(cc.Label)
    scoreLabel:cc.Label=null;

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}

    start () {
        this.scoreLabel.string=""+GameController.getInst().score;
        this.rankingFriend3.getComponent(cc.Widget).updateAlignment();
         wx_opendata.wxPostMessageToSubDomain({
                 score:GameController.getInst().score,
                 action:wx_opendata.WxDomainAction.UpdateAndFetchFriend,
                 width:this.rankingFriend3.width,
                 height:this.rankingFriend3.height
             });
    }

    onClickBackBtn(){
        cc.director.emit(constants.GAME_EVENT.BtnClick);
        cc.director.loadScene("start");
    }

    onClickRetryBtn(){
        cc.director.emit(constants.GAME_EVENT.BtnClick);
        cc.director.loadScene("main");
    }

    onClickInviteBtn(){
        cc.director.emit(constants.GAME_EVENT.BtnClick);
        wx_opendata.wxShare();
    }

    onClickRankingBtn(){
        cc.director.emit(constants.GAME_EVENT.BtnClick);
        global.rankingState=global.RankingState.Friend;
        global.rankingCallBackScene="gameover";
        cc.director.loadScene("ranking");
     
    }

    // update (dt) {}
}
